package com.ygxsk.carhome.ui.rice;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ClickUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.kongzue.dialogx.dialogs.CustomDialog;
import com.kongzue.dialogx.interfaces.OnBindView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.response.SmartGoVerifiBean;
import com.ygxsk.carhome.sys.Session;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.SmartGoVerifiAdapter;
import com.ygxsk.carhome.views.MyLinearLayoutManager;
import com.ygxsk.integrated.retrofit.Parameterkey;

import java.util.ArrayList;

import butterknife.BindView;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-26  15:28
 * @Description:餐券的核销功能
 *
 * 废弃
 *
 */
public class RiceTicketVerificationActivity extends ErrorActivity {

    @BindView(R.id.refreshlayoutinsmartgoverifi)
    SmartRefreshLayout refreshLayoutInSmartGoVerifi;

    @BindView(R.id.recyclerviewinsmartgoverifi)
    RecyclerView recyclerViewInSmartGoVerifi;


//    //选择类型
//    @BindView(R.id.nice_spinner_cartype)
//    NiceSpinnersk nice_spinner_carType;
//    //选择来源
//    @BindView(R.id.nice_spinner_formwhere)
//    NiceSpinnersk nice_spinner_formWhere;
//    //选择状态
//    @BindView(R.id.nice_spinner_stateitem)
//    NiceSpinnersk nice_spinner_stateItem;

    //潜在客户，
    private ArrayList<SmartGoVerifiBean> mDataResources = new ArrayList();

    private SmartGoVerifiAdapter smartGoVerifiAdapter;

    /**
     * 最后一条上传的id的信息内容
     */
    private int pagination_upLoad = Parameterkey.pageNum_default_first;

    //核销卡券 的弹窗内容，展示卡券的结果；应该是门卫去核销 才有这个权限使用；
    private CustomDialog customDialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;
        mSession = Session.get(this);

//        if (dataListFromWhere == null) {
//            dataListFromWhere = new ArrayList<>();
//        }
//        if (dataListStateItem == null) {
//            dataListStateItem = new ArrayList<>();
//        }

        initloading();

        initViews();


    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected int getContentViewId() {


        return R.layout.activity_smart_go_verifi;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.leadscustomer));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

        //核销的历史记录顶部啥都没有；
//        toolbarHelper.setLayoutRight(false, 0, "", null);

        //添加潜在客户的按钮
        toolbarHelper.setLayoutRight(true, 1, "扫码核销", new ClickUtils.OnDebouncingClickListener() {
            @Override
            public void onDebouncingClick(View v) {

                //快速双加的限制，
                // TODO: 2023-07-11 16:18 提交潜在客户的信息
//                Bundle extra_bundle = new Bundle();
//                ActivityUtils.startActivity(extra_bundle, LeadAddSubmitActivity.class);
                // TODO: 2023-07-25 21:39 携带二维码的信息;
                Bundle bundle = new Bundle();
                bundle.putInt(ExtraKey.EXTRA_QRCODE_INFO, 0);
                bundle.putInt(ExtraKey.BGAQRCODE_KEY, ExtraValue.BGAQRCODE_VALUE_FROM_WEBVIEW);

                //ActivityUtils.startActivity(bundle, MyBGAQRCodeActivity.class);

                // TODO: 2023-07-26 11:06 测试代码 是打开核销的弹窗；
//                new XPopup.Builder(mActivityInstance)//
//                        .autoOpenSoftInput(true)//
//                        .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .asInputConfirm("复用项目已有布局",//
//                                null,//
//                                "您可以复用项目已有布局，来使用XPopup强大的交互能力和逻辑封装，弹窗的布局完全由你自己控制。\n" +
//                                        "注意：你自己的布局必须提供一些控件Id，否则XPopup找不到View。\n具体需要提供哪些Id，请查看文档[内置弹窗]一章。",
//                                null,//
//                                new OnInputConfirmListener() {
//                                    @Override
//                                    public void onConfirm(String text) {
//
//                                    }
//                                }, null,
//                                R.layout.popu_card_dist_middle_popu) //最后一个参数绑定已有布局
//                        .show();

                if (customDialog != null) {
                    customDialog.dismiss();
                    customDialog = null;
                }

                customDialog = CustomDialog.show(new OnBindView<CustomDialog>(R.layout.popu_card_dist_middle_popu) {
                            @Override
                            public void onBind(final CustomDialog dialog, View v) {

                                //标题 卡券的
                                TextView textViewCardName = (TextView) v.findViewById(R.id.textviewcardname);
                                //卡券的备注
                                TextView textViewCardLittleInfo = (TextView) v.findViewById(R.id.textviewcardlittleinfo);
                                //卡券的有效期
                                TextView textViewCardTime = (TextView) v.findViewById(R.id.textviewcardtime);

                                //卡券的有效期
                                RoundTextView textViewCardCancel = (RoundTextView) v.findViewById(R.id.textviewcardcancel);
                                //卡券的取消按钮
                                RoundTextView textViewCardSure = (RoundTextView) v.findViewById(R.id.textviewcardsure);

                                // TODO: 2023-07-26 15:07 测试代码,这里是核销成功的信息；
                                textViewCardName.setText("奔驰卡车优惠券");
                                textViewCardLittleInfo.setText("满300元可用");
                                textViewCardTime.setText("2023-12-12 :10 :10 :10");

                                if (textViewCardCancel != null) {
                                    textViewCardCancel.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                                        @Override
                                        public void onDebouncingClick(View v) {
                                            if (customDialog != null) {
                                                customDialog.dismiss();
                                            }
                                        }
                                    });
                                }

                                if (textViewCardSure != null) {

                                    textViewCardSure.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
                                        @Override
                                        public void onDebouncingClick(View v) {


                                            // TODO: 2023-07-26 点击【确定】才是真的核销!!

                                        }
                                    });
                                }
                            }
                        })
                        .setMaskColor(ColorUtils.getColor(R.color.black30))//
                        .setCancelable(false);//不让点击物理 返回键 关闭弹窗；
            }
        });


    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

        // TODO: 2023-07-13 15:55 假数据
        SmartGoVerifiBean smartGoVerifiBean = new SmartGoVerifiBean();
        smartGoVerifiBean.setCustomerPerson("张三");
        smartGoVerifiBean.setCardInfo("车辆轮胎保养");
        smartGoVerifiBean.setWorkerPerson("员工陈大");
        smartGoVerifiBean.setWorkerTime("2023-11-23");
        smartGoVerifiBean.setRemark("新车试驾,新车试驾,新车试驾,新车试驾");

        SmartGoVerifiBean cardDistHistoryBean1 = new SmartGoVerifiBean();
        cardDistHistoryBean1.setCustomerPerson("张三");
        cardDistHistoryBean1.setCardInfo("车辆轮胎保养");
        cardDistHistoryBean1.setWorkerPerson("员工陈大");
        cardDistHistoryBean1.setWorkerTime("2023-11-23");
        cardDistHistoryBean1.setRemark("新车试驾,新车试驾,新车试驾,新车试驾");

        SmartGoVerifiBean cardDistHistoryBean2 = new SmartGoVerifiBean();
        cardDistHistoryBean2.setCustomerPerson("张三");
        cardDistHistoryBean2.setCardInfo("车辆轮胎保养");
        cardDistHistoryBean2.setWorkerPerson("员工陈大");
        cardDistHistoryBean2.setWorkerTime("2023-11-23");
        cardDistHistoryBean2.setRemark("新车试驾,新车试驾,新车试驾,新车试驾");

        mDataResources.add(smartGoVerifiBean);
        mDataResources.add(cardDistHistoryBean1);
        mDataResources.add(cardDistHistoryBean2);

        //----------------------------------------------------------------------------------
        //----------------------------------------------------------------------------------
        //布局的适配器填充，下拉刷新等等；
        recyclerViewInSmartGoVerifi.setLayoutManager(new MyLinearLayoutManager(this));

        smartGoVerifiAdapter = new SmartGoVerifiAdapter(R.layout.smartgo_history_adapter, mDataResources);
        recyclerViewInSmartGoVerifi.setAdapter(smartGoVerifiAdapter);

        smartGoVerifiAdapter.notifyDataSetChanged();

        smartGoVerifiAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                // TODO: 2023-07-13 15:07 跳转到这个客户的详情页面
                Bundle extra_bundle = new Bundle();

//                extra_bundle.putParcelable(ExtraKey.EXTRA_RUNMANGROUPMANAGEBEAN, runManGroupManageBeanItem);

//                ActivityUtils.startActivity(extra_bundle, LeadDetailActivity.class);

            }
        });

        refreshLayoutInSmartGoVerifi.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        if (mDataResources != null && !mDataResources.isEmpty()) {
                            mDataResources.clear();
                        }

                        // TODO: 2023-07-13 15:11 待处理

//                        getServerDatas();

                        refreshLayout.finishRefresh();
                    }
                });

            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        //最后一条数据的id信息；
                        //getServerDatas(repairIdPass);

                        refreshLayout.finishLoadMore();

                    }
                });
            }
        });

//        if (roundButtonAddGroupInRunManGroup != null) {
//
//            roundButtonAddGroupInRunManGroup.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
//                @Override
//                public void onDebouncingClick(View v) {
//
//                    // TODO: 2023-07-13 15:52 跳转到人员分配列表页面
//                    //跳转到资产的添加页面
//                    Bundle extra_bundle = new Bundle();
////
////                    //String shopId = assetInSideBean.getShopId();
////
////                    //是添加进来的
////                    extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE,ExtraValue.VALUE_JUMP_FORM_ASSET_ADD);
////
////                    extra_bundle.putString(ExtraKey.EXTRA_ASSETINSIDEBEAN_SHOPID,assetInSideBean.getShopId());
////
////                    //携带服务站的列表过去
////                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETSTATIONINFOLISTFORADDASSET, assetStationInfoListForAddAsset);
////                    //携带资产的归属方
////                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETUNDERBUSINESSINFOLISTOUTSIDE, assetUnderBusinessInfoListOutSide);
////                    //
//                    ActivityUtils.startActivity(extra_bundle, LeadManagerGroupActivity.class);
//
//                }
//            });
//        }


    }

    @Override
    protected void gainDatas() {

    }

    @Override
    protected void methodBack() {

    }
}